package com.boang.service;

import com.boang.entity.Student;

import java.util.Scanner;

/*
  @author: 13813
  @date: 2024/11/15 16:52
*/
public class StudentService {
    //新增功能
    public Student[] stus = new Student[10];
    public int index = 0;

    public void add() {
        for (int i = 0; i < 2; i++) {
            System.out.println("请输入姓名");
            Scanner scanner = new Scanner(System.in);
            //用户名
            String name = scanner.nextLine();
            Student student = new Student();
            student.name = name;
            //年龄
            System.out.println("请输入年龄");
            String age = scanner.nextLine();
            student.age = Integer.parseInt(age);
            //性别
            System.out.println("请输入性别");
            String sex = scanner.nextLine();
            student.sex = sex;
            stus[index] = student;
            index++;
        }
    }

    //遍历
    public void list() {
        for (int i = 0; i < index; i++) {
            Student stu = stus[i];
            System.out.println("姓名：" + stu.name);
            System.out.println("年龄：" + stu.age);
            System.out.println("性别：" + stu.sex);
        }
    }
}
